#pragma once
#ifndef __DATAQUEUE_HPP__
#define __DATAQUEUE_HPP__

#include <queue>
#include <mutex>
#include <condition_variable>
#include <iostream>

template<typename ElementType>
class DataQueue{
public:
    DataQueue() = default;
    void push(ElementType& data){
        {
        std::unique_lock<std::mutex> lock(mtx);
        data_queue.push(data);
        }
        cond.notify_one();
    }

    ElementType poll(){
        std::unique_lock<std::mutex> lock(mtx);
        cond.wait(lock, [this](){return !this->data_queue.empty();});
        ElementType data = data_queue.front();
        data_queue.pop();
        return data;
    }

private:
    std::queue<ElementType> data_queue;
    std::mutex mtx;
    std::condition_variable cond;
};

#endif // __DATAQUEUE_HPP__